﻿using Cart.NguoiDungSrv;
using Cart.SanPhamSrv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cart
{
    public partial class Ds_LoaiSP : VdcInc.vdcAJAXPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            #region check quyen
            var user = Session["nsd"] as NguoiDung;
            if (user != null)
            {
                if (user.Quyen != 1) ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('Không có quyền truy cập !'); window.location='" + Request.ApplicationPath + "TrangChu.aspx';", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('Không có quyền truy cập !'); window.location='" + Request.ApplicationPath + "TrangChu.aspx';", true);
            }

            #endregion check quyen
            using (var spService = new SanPhamSrv.SanPhamServiceClient())
            {
                var spmodel = spService.DanhSachLoaiSanPham();
                lvDanhSach.DataSource = spmodel;
                lvDanhSach.DataBind();
            }
        }
        public string vXoaLoaiSP(string strLoaiSPId)
        {
            using (var ndService = new SanPhamSrv.SanPhamServiceClient())
            {
                var lsp = new LoaiSanPham();
                lsp.Id = Convert.ToInt64(strLoaiSPId);
                var listLoaiSp = ndService.DanhSachLoaiSanPham();
                foreach (var loai in listLoaiSp)
                {
                    if (loai.Id == Convert.ToInt64(strLoaiSPId) && loai.SoLuongSP == 0)
                    {
                        var result = ndService.CapNhatLoaiSanPham(lsp);
                        return "Xóa " + result;
                    }
                }
                return "Xóa thất bại";
            }
        }
    }
}